package cn.wizzer.app.web.modules.controllers.open;


import cn.wizzer.app.sys.modules.services.SysCurrencyService;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;

/**
 * 币种
 */
@IocBean
@At("/open/currency")
public class ApiCurrencyController {
    @Inject
    @Reference
    private SysCurrencyService currencyService;

    @At
    @Ok("json")
    public Result list() {
        return Result.successNonNull(currencyService.getAll());
    }


    /**
     * 给前端提供系统时区
     *
     * @return
     */
    @At("/timeZone")
    @Ok("json")
    public Result timeZone() {
        ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeZone.getDefault().getID()));
        String offset = now.getOffset().toString().replace(":", "");
        return Result.success().addData("UTC" + offset);
    }
}
